package com.xps.charmingshop.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xps.charmingshop.R;
import com.xps.charmingshop.bean.CompleteBean;
import com.xps.charmingshop.view.activity.OrderDetailsActivity;
import com.zhy.autolayout.utils.AutoUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CompleteAdapter extends AbstractRecyclerAdapter<CompleteBean.ReturnBodyBean> {
    CompleteBean.ReturnBodyBean or;

    public CompleteAdapter(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.adapter_complete, parent, false);
        v.setOnClickListener(this);
        return new ViewHolder(v);
    }

    @Override
    protected void onBindViewHolder(RecyclerView.ViewHolder holder, int position, boolean isItem) {
        ViewHolder myViewHolder = (ViewHolder) holder;
        or = getItem(position);
        myViewHolder.Complete_ID.setText(or.getOrder_id());
        parseTime(or.getOrder_create_time(), myViewHolder.Complete_Date);
        dateTime(or.getOrder_create_time(), myViewHolder.Complete_Money);
        if (or.getOrder_status().equals("-1")) {
            myViewHolder.Complete_State.setText("未处理");
        } else if (or.getOrder_status().equals("1")) {
            myViewHolder.Complete_State.setText("准备");
        } else if (or.getOrder_status().equals("2")) {
            myViewHolder.Complete_State.setText("配送中");
        } else if (or.getOrder_status().equals("3")) {
            myViewHolder.Complete_State.setText("完成");
        } else if (or.getOrder_status().equals("4")) {
            myViewHolder.Complete_State.setText("取消");
        }
        myViewHolder.Complete_Order.setText("查看");
    }

    /**
     * 解析时间
     */
    void parseTime(String createTime, TextView tvOrderTime) {
        long lTime = Long.valueOf(createTime);
        long nTime = lTime * 1000;
        Date passDate = new Date(nTime);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        tvOrderTime.setText(simpleDateFormat.format(passDate));
    }

    /**
     * 解析时间
     */
    void dateTime(String createTime, TextView tvOrderTime) {
        long lTime = Long.valueOf(createTime);
        long nTime = lTime * 1000;
        Date passDate = new Date(nTime);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        tvOrderTime.setText(simpleDateFormat.format(passDate));
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.Complete_ID)
        TextView Complete_ID;
        @BindView(R.id.Complete_Money)
        TextView Complete_Money;
        @BindView(R.id.Complete_Date)
        TextView Complete_Date;
        @BindView(R.id.Complete_State)
        TextView Complete_State;
        @BindView(R.id.Complete_Order)
        TextView Complete_Order;


        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            AutoUtils.autoSize(view);
        }


    }


}
